package com.jungle.mvvm.sample.ui.home;

import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.RequiresApi;

import com.jungle.mvvm.base.MultiItemViewModel;
import com.jungle.mvvm.binding.command.BindingCommand;
import com.jungle.mvvm.binding.command.BindingConsumer;
import com.jungle.mvvm.sample.bean.BannerBean;
import com.jungle.mvvm.sample.ui.detail.DetailActivity;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @ClassName HomeHeadViewModel
 * @Description HomeHeadViewModel
 * @Author Daniel
 * @Version V1.0.0
 */
public class HomeHeadViewModel extends MultiItemViewModel<HomeViewModel> {

    private List<String> mList;
    private List<BannerBean> mBannerBeanList;

    @RequiresApi(api = Build.VERSION_CODES.N)
    public HomeHeadViewModel(@NonNull HomeViewModel viewModel, List<BannerBean> list) {
        super(viewModel);
        this.mBannerBeanList = list;
        this.mList = list.stream().map(bannerBean -> bannerBean.getImagePath()).collect(Collectors.toList());
    }

    public List<String> getList() {
        return mList;
    }

    //条目的点击事件
    public BindingCommand itemClick = new BindingCommand(new BindingConsumer<Integer>() {
        @Override
        public void call(Integer position) {
            Bundle bundle = new Bundle();
            BannerBean bannerBean = mBannerBeanList.get(position);
            bundle.putString("url", bannerBean.getUrl());
            bundle.putString("title",bannerBean.getTitle());
            viewModel.startActivity(DetailActivity.class, bundle);
        }
    });
}

